/**
 * 初始化提现帐号详情对话框
 */
var WithdrawtAccountInfoDlg = {
    withdrawtAccountInfoData : {},
    validateFields: {
    	accountNo: {
            validators: {
                notEmpty: {
                    message: '账号不能为空'
                }
            }
        },
        accountName: {
            validators: {
                notEmpty: {
                    message: '账户名不能为空'
                }
            }
        },
        accountType: {
            validators: {
                notEmpty: {
                    message: '账户类型不能为空'
                }
            }
        },
        accountProp: {
            validators: {
                notEmpty: {
                    message: '账户属性不能为空'
                }
            }
        },
        idType: {
            validators: {
                notEmpty: {
                    message: '证件类型不能为空'
                }
            }
        },
        idNo: {
            validators: {
                notEmpty: {
                    message: '身份证不能为空'
                }
            }
        },
        tel: {
            validators: {
                notEmpty: {
                    message: '手机号不能为空'
                }
            }
        },
        bankCode: {
            validators: {
                notEmpty: {
                    message: '银行代码不能为空'
                }
            }
        } 
    }
};

/**
 * 清除数据
 */
WithdrawtAccountInfoDlg.clearData = function() {
    this.withdrawtAccountInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
WithdrawtAccountInfoDlg.set = function(key, val) {
    this.withdrawtAccountInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
WithdrawtAccountInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
WithdrawtAccountInfoDlg.close = function() {
    parent.layer.close(window.parent.WithdrawtAccount.layerIndex);
}

/**
 * 收集数据
 */
WithdrawtAccountInfoDlg.collectData = function() {
    this
    .set('id')
    .set('accountNo')
    .set('accountName')
    .set('accountType')
    .set('accountProp')
    .set('bankCode')
    .set('validate')
    .set('cvv2')
    .set('idType')
    .set('idNo')
    .set('tel')
    .set('province')
    .set('city')
}



/**
 * 验证数据是否为空
 */
WithdrawtAccountInfoDlg.validate = function () {
    $('#withdrawAccountForm').data("bootstrapValidator").resetForm();
    $('#withdrawAccountForm').bootstrapValidator('validate');
    return $("#withdrawAccountForm").data('bootstrapValidator').isValid();
};


/**
 * 提交添加
 */
WithdrawtAccountInfoDlg.addSubmit = function() {

	this.clearData();
	this.collectData();

    if (!this.validate()) {
        return;
    }

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/withdrawtAccount/add", function(data){
        Feng.success("添加成功!");
        window.parent.WithdrawtAccount.table.refresh();
        WithdrawtAccountInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.withdrawtAccountInfoData);
    ajax.start();
}


/**
 * 审核提交
 */
WithdrawtAccountInfoDlg.auditSubmit = function() {

	this.clearData();
	this.collectData();

    if (!this.validate()) {
        return;
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/withdrawtAccount/audit", function(data){
        Feng.success("提交成功!");
        window.parent.WithdrawtAccount.table.refresh();
        WithdrawtAccountInfoDlg.close();
    },function(data){
        Feng.error("提交失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.withdrawtAccountInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
WithdrawtAccountInfoDlg.editSubmit = function() {
    this.clearData();
    this.collectData();

    if (!this.validate()) {
        return;
    }

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/withdrawtAccount/update", function(data){
        Feng.success("修改成功!");
        window.parent.WithdrawtAccount.table.refresh();
        WithdrawtAccountInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.withdrawtAccountInfoData);
    ajax.start();
}

$(function() {
	 Feng.initValidator("withdrawAccountForm", WithdrawtAccountInfoDlg.validateFields);

});
